﻿using System;
using System.Runtime.Serialization;

namespace Modbus
{
	[Serializable]
	public class MismatchResponseException : ModbusException
	{
		private readonly string fieldName;

		#region ( Constructors )

		public MismatchResponseException()
			: base(ModbusError.MismatchResponse)
		{
		}

		public MismatchResponseException(string fieldName)
			: base(ModbusError.MismatchResponse)
		{
			this.fieldName = fieldName;
		}

		protected MismatchResponseException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			this.fieldName = info.GetString(SR.MismatchResponseException_FieldName);
		}

		#endregion

		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);

			info.AddValue(SR.MismatchResponseException_FieldName, this.fieldName, typeof(string));
		}

		public string FieldName
		{
			get { return this.fieldName; }
		}

		public override string Message
		{
			get
			{
				if (fieldName == null)
				{
					return base.Message;
				}

				// TODO: Append detailed message.
				return base.Message + Environment.NewLine + "";
			}
		}
	}
}
